function callClientFunction(client, funcname, ...)
    local arg = { ... }
    if (arg[1]) then
        for key, value in next, arg do
            if (type(value) == "number") then arg[key] = tostring(value) end
        end
    end
    triggerClientEvent(client, "onServerCallsClientFunction", resourceRoot, funcname, unpack(arg or {}))
end

function getTimeStamp(argument)
 local theTime=getRealTime()
 local hours=theTime.hour
 local minutes=theTime.minute
 if(string.len(hours)<2)then
  hours=0 .. hours
 end
 if(string.len(minutes)<2)then
  minutes=0 .. minutes
 end
 local timeStamp=("[" .. hours .. ":" .. minutes)
 if(argument=="seconds")then
  local seconds=theTime.second
  if(string.len(seconds)<2)then
  seconds=0 .. seconds
  end
  timeStamp=(timeStamp .. ":" .. seconds)
 end
 local timeStamp=timeStamp .. "]"
 return(timeStamp)
end

addEventHandler("onPlayerChat",getRootElement(),
 function(message,theType)
  cancelEvent()
  if(theType==0)then
   for k,v in ipairs(getElementsByType("player"))do
    callClientFunction(v,"outputTimeChat",source,message,theType)
   end
   outputServerLog(getTimeStamp("lol") .. " CHAT: " .. getPlayerName(source) .. ": " .. message)
  elseif(theType==1)then
   for k,v in ipairs(getElementsByType("player"))do
    callClientFunction(v,"outputTimeChat",source,message,theType)
   end
   outputServerLog(getTimeStamp("lol") .. " ME: " .. getPlayerName(source) .. message)
  elseif(theType==2)then
   local team=getPlayerTeam(source)
   if(team)then
    for k,v in ipairs(getPlayersInTeam(team))do
     callClientFunction(v,"outputTimeChat",source,message,theType,team)
    end
   outputServerLog(getTimeStamp("lol") .. " TEAMCHAT: (" .. getTeamName(team) .. ") " .. getPlayerName(source) .. ": " .. message)
   end
  end
 end
)
